//
//  ZH_MineNameInfoTableViewCell.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/10/22.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_MineNameInfoTableViewCell.h"
@interface ZH_MineNameInfoTableViewCell()
@property (nonatomic,weak)UILabel *leftLabel;
///输入框
@property (nonatomic,weak) UITextField *textField;
@property (nonatomic,weak)UILabel *rightLabel;
@end
@implementation ZH_MineNameInfoTableViewCell

///创建
+(instancetype)cellWithTableView:(UITableView*)tableView
{
    static NSString *ID = @"ZH_MineNameInfoTableViewCell";
    ZH_MineNameInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[ZH_MineNameInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
///初始化
-(void)initDefault
{
    [self unShowClickEffect];
    self.bottomShortLineImage.hidden = NO;
}
- (void)loadSubviewConstraints{
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(13));
        make.left.equalTo(self.contentView).offset(FITSCALE(22));
        make.bottom.equalTo(self.contentView).offset(FITSCALE(-13));
    }];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.leftLabel.mas_right).offset(FITSCALE(30));
        make.width.mas_equalTo(FITSCALE(150));
    }];
    [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView).offset(FITSCALE(-22));
    }];
}
///输入框 回调 方法
- (void)textFieldDidEndEditing:(UITextField *)textField
{
//    if(self.onEnterTextFieldBlock){
//        self.onEnterTextFieldBlock(textField.text, textField.tag);
//    }
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.textField endEditing:YES];
    return YES;
}
- (void)setNameString:(NSString *)nameString{
    self.textField.text = nameString;
}
#pragma mark - getter,setter
- (UILabel *)leftLabel{
    if (!_leftLabel) {
        UILabel *label = [UILabel createLabelWithText:@"昵称" font:kFontSize_28];
        [self.contentView addSubview:_leftLabel = label];
    }
    return _leftLabel;
}
- (UITextField *)textField
{
    if(!_textField){
        UITextField *textField = [UITextField createTextFieldWithPlaceholder:@"" placeholderColor:kFontColorGray delegateTarget:self];
        textField.borderStyle = UITextBorderStyleNone;
        textField.font = kFontSize_28;
        textField.textAlignment = NSTextAlignmentLeft;
        textField.returnKeyType = UIReturnKeyDone;
        [textField setTextColor:kFontColorBlack];
        [self.contentView addSubview:_textField = textField];
    }
    return _textField;
}
- (UILabel *)rightLabel{
    if (!_rightLabel) {
        UILabel *label = [UILabel createLabelWithText:@"*姓名必须为真实姓名" font:kFontSize_22];
        label.textColor = [UIColor colorWithHexString:@"#999999"];
        label.textAlignment = NSTextAlignmentRight;
        NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:label.text];
        NSDictionary *dic = @{NSFontAttributeName:kFontSize_22,NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#FF3636"]};
        [attr setAttributes:dic range:[label.text rangeOfString: @"*"]];
        label.attributedText = attr;
        [self.contentView addSubview:_rightLabel = label];
    }
    return _rightLabel;
}
@end
